package com.itrip.utils;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
public class PhoneMessage {
    /**
     *
     * @param phone 手机号码
     * @param code 生成的验证码
     *
     */
    public static void  sendPhoneMessage(String phone,String code) {
        String      accessKeyId    ="LTAI4GKfgdGd92bWPq33YrV9";
        String      accessSecret   ="UKE5tEYYVJXhkHIn8qPMBOizhQT2YN";
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessSecret);
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", phone);
        request.putQueryParameter("SignName", "雪上行者");
        request.putQueryParameter("TemplateCode", "SMS_197890768");
        request.putQueryParameter("TemplateParam", "{\"code\":'"+code+"'}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }

  /*  public static void main(String[] args) {
        sendPhoneMessage("15696477860","2135648");
    }*/
}


